/**
 * 
 */
package qjs.com.vn.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import qjs.com.vn.dao.BaoBiDao;
import qjs.com.vn.model.BaoBi;

/**
 * @author WIN7
 *
 */
public class BaoBiDaoImpl extends HibernateDaoSupport implements BaoBiDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<BaoBi> listBaoBi() {
		return getHibernateTemplate().find("from BaoBi");
	}

	@Override
	public void editBaoBi(BaoBi baoBi) {
		getHibernateTemplate().update(baoBi);
	}

	@Override
	public void deleteBaoBi(BaoBi baobi) {
		// TODO Auto-generated method stub
		getHibernateTemplate().delete(baobi);
	}

	@SuppressWarnings("unchecked")
	@Override
	public BaoBi getOneBaoBi(String mabaobi) {
		// TODO Auto-generated method stub
		String query = "from BaoBi where baobiid="+mabaobi;
		List<BaoBi> baoBis = new ArrayList<BaoBi>();
		BaoBi baoBiTemp = new BaoBi();
		baoBis = getHibernateTemplate().find(query);
		for (BaoBi baoBi : baoBis) {
			baoBiTemp = baoBi;
		}
		return baoBiTemp;
		
	}

	@Override
	public void addBaoBi(BaoBi baobi) {
		// TODO Auto-generated method stub
		getHibernateTemplate().save(baobi);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<BaoBi> searchBaoBi(String mabaobi, String tenbaobi,
			String nhacungcap) {
		String query = "from BaoBi where mabaobi='"+mabaobi+"' or tenbaobi='"+tenbaobi+"' or mancc ='"+nhacungcap+"'";
		List<BaoBi> listBaoBi = new ArrayList<BaoBi>();
		listBaoBi = getHibernateTemplate().find(query);
		return listBaoBi;
	}

	

}
